<?php

/*
 *
 *  200：
 *      符合预期都输出 ok
 *
 * '200'：
 *      switch 输出ok，match 输出unknown status code
 *      结论：match 匹配表达式为严格模式，也就是 ===
 *
 * 999：
 *      1、正常情况下都输出：unknown status code
 *      2、分别将 switch 与 match 的 default 删掉
 *          switch：Warning: Undefined variable $messageFromSwitch
 *           match：Fatal error: Uncaught UnhandledMatchError: Unhandled match value of type string
 *
 * */

$statusCode = 999;  //200 '200' 999

switch ($statusCode) {
    case 200:
        //no break
    case 300:
        $messageFromSwitch = 'ok';
        break;
    case 400:
        $messageFromSwitch = 'not found';
        break;
    case 500:
        $messageFromSwitch = 'server error';
        break;
   /* default:
        $messageFromSwitch = 'unknown status code';
        break;*/
}


$messageFromMatch = match ($statusCode) {
    200,300 => 'ok',
    400 => 'not found',
    500 => 'server error',
    default => 'unknown status code'
};

echo "switch:  $messageFromSwitch". PHP_EOL;
echo "match:  $messageFromMatch". PHP_EOL;

